import { Shape } from "./shape/shape";
import { Graphic } from "./type";
import { NodeConfig } from "/core/node";
import Node from "/core/node";
import { NodeType } from "/enum/NodeTypeEnum";
import { ShapeEvent } from "/types/event";

export class Group extends Shape {
	type = NodeType.GROUP;
	constructor(props?: NodeConfig) {
		super(props);
	}
	add(node: any) {
		this.setParent(node);
        this.children.push(node);
	}
    remove(node:Graphic){
        const removeIndex = this.children.findIndex(nodes =>nodes === node);
        this.children.splice(removeIndex,1)
    }
	draw() {
		if (!this.parent) {
			return;
		}
		const painter = this.parent.painter;
		this.children?.forEach(node => {
			node.draw(painter.ctx);
		});
	}
	//group本身不需要做任何操作，直接允许事件冒泡
	isPointInClosedRegion(shapeEvent: ShapeEvent) {
		return true;
	}
}
